package bean;

import entity.Compte;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import session.CompteFacadeLocal;
import session.TypeFacadeLocal;

/**
 *
 * @author Mély
 */
@ManagedBean
@SessionScoped
public class CompteBean {

    @EJB
    private CompteFacadeLocal compteBean;
    @EJB
    private TypeFacadeLocal typeBean;
    private Compte current;
    private String name;
    private String server;
    private String portNumber;
    private String typeBDD;

    public CompteBean() {
    }

    public List<Compte> getAll() {
        return compteBean.findAll();
    }

    public Compte getCurrent() {
        return current;
    }

    public void setCurrent(Compte current) {
        this.current = current;
    }
    
    public void addCompte() {
        Compte compte = new Compte();
        compte.setName(this.getName());
        compte.setServer(this.getServer());
        compte.setTypeBDDid(typeBean.findByType(this.getTypeBDD()));
        compte.setPortNumber(Integer.parseInt(this.getPortNumber()));
        compteBean.create(compte);
        reset();
    }
    
    public void reset() {
        this.name = null;
        this.server = null;
        this.current = null;
        this.typeBDD = null;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getServer() {
        return server;
    }

    public void setServer(String server) {
        this.server = server;
    }

    public String getTypeBDD() {
        return typeBDD;
    }

    public void setTypeBDD(String typeBDD) {
        this.typeBDD = typeBDD;
    }
    
    public void removeCompte() {
        compteBean.remove(this.getCurrent());
        reset();
    }

    public String getPortNumber() {
        return portNumber;
    }

    public void setPortNumber(String portNumber) {
        this.portNumber = portNumber;
    }
}
